ajaxConPost = {
	
	READY_STATE_UNINITIALIZED: 0,
	READY_STATE_LOADING: 1,
	READY_STATE_LOADED: 2,
	READY_STATE_INTERACTIVE: 3,
	READY_STATE_COMPLETE: 4,
	
	request:null,
	container: null,
	httpMethod:"POST",
	showLoaderTimer:null,
		
	readData: function(container, url, parameters)
	{
		
		if (!ajaxConPost.initXMLHTTPRequest())
		{
			return false;
		}
		
		ajaxConPost.container = document.getElementById(container);
		
		ajaxConPost.request.onreadystatechange = ajaxConPost.onReadyStateChangedHandler;
		
		ajaxConPost.request.open(ajaxConPost.httpMethod, url, true);
		
		ajaxConPost.request.setRequestHeader('If-Modified-Since', 'Mon, 01 Sep 2007 00:00:00 GMT');
		ajaxConPost.request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajaxConPost.request.setRequestHeader("Content-length", parameters.length);
		ajaxConPost.request.setRequestHeader("Connection", "close");

		ajaxConPost.request.send(parameters);
		
		//ajaxCon.showLoaderTimer = setTimeout(ajaxCon.showTimeOut, 500);
		
		
		
		
		return true;
	},	
	
	dataRetrieved: function()
	{
		window.clearInterval(Yatzy.intervalId);
		ajaxConPost.container.innerHTML = ajaxConPost.request.responseText;	
		Yatzy.init();
	},
	
	initXMLHTTPRequest: function()
	{
		try {
			ajaxConPost.request = new XMLHttpRequest();	
		} catch (error)
		{
			try {
				ajaxConPost.request = new ActiveXObject("Microsoft.XMLHTTP");	
			} catch (error)
			{
				// Can not create XHR-object.
				return false;
			}
		}

		return true;
	},
	
	onReadyStateChangedHandler: function(e)
	{
		
		if(ajaxConPost.request.readyState == ajaxConPost.READY_STATE_LOADING)
		{
//			ajaxConPost.container.innerHTML	= "Kontrollerar...." + ajaxConPost.container.innerHTML;
		}
		else if(ajaxConPost.request.readyState == ajaxConPost.READY_STATE_COMPLETE)
		{
				if(ajaxConPost.request.status == 200 || ajaxConPost.request.status == 304)
				{
					ajaxConPost.dataRetrieved();
				}
				else
				{
					ajaxConPost.container.innerHTML = "Läsfel, status:"+ajaxConPost.request.status+"<br />";	
				}
		}
	}
}
